/**
 * 
 */
package com.tomato.joke.service;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.content.Context;

import com.tomato.joke.persistence.dao.JokeTopicDao;
import com.tomato.joke.persistence.model.JokeTopic;

/**
 * 话题service
 * 
 * @author defier
 * 
 */
public class JokeTopicService {

	private JokeTopicDao jokeTopicDao;

	public JokeTopicService(Context context) {
		jokeTopicDao = new JokeTopicDao(context);
	}

	public List<Map<String, Object>> queryNewTopics() {
		List<Map<String, Object>> items = new ArrayList<Map<String, Object>>();
		try {
			List<JokeTopic> topics = jokeTopicDao.getDao().queryForAll();
			for (JokeTopic topic : topics) {
				Map<String, Object> map = new HashMap<String, Object>();
				map.put("thumbnail", topic.getThumbnail());
				map.put("content", topic.getContent());
				map.put("id", topic.getId());
				items.add(map);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return items;
	}

	public JokeTopic findById(int topicId) {
		try {
			return jokeTopicDao.getDao().queryForId(topicId);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}

}
